<?php
defined('IN_MAIN') or exit('Invalid Access!');

function calc_personal_sales($uid, $date_from, $date_to){
/*
This function calculate the total sales volume for the input uid for the date range date_from to date_to
*/

	global $vars;
	$db=$vars["db"];
	
	$calc_date['start'] = date("Y-m-d H:i:s", strtotime($date_from));
	$calc_date['end'] = date("Y-m-d H:i:s", strtotime($date_to));
	
	$total_sale = @mysql_result(mysql_query("select sum(s.bv) from $db->purchase a inner join $db->sales_bv s on s.slid=a.id and s.uid='$uid' where a.first_sale='y' and a.status='confirmed' and a.cdate>='$calc_date[start]' and a.cdate<='$calc_date[end]'"), 0) or 0;
											
	$week = date('W', strtotime($date_to));
	$month = date('n', strtotime($date_to));
	$year = date('Y', strtotime($date_from));
	//$total_maintain = @mysql_result(mysql_query("select sum(amount) from $db->member_maintain where uid='$uid' and year='$year' and month='$month'"), 0) or 0;
	$total_maintain = 0;
	
	$total_volume = $total_sale + $total_maintain;
	return $total_volume;
}
?>